
#include "member_BSplitButton.h"
#include "member_BSplitItem.h"
#include "member_BObject.h"

using namespace BWE;

#define member					(*(member_BSplitItem*)_ptr)
#define member_allocate()		_ptr = new member_BSplitItem(this)
#define member_release()		delete (member_BSplitItem*)_ptr

BSplitItem::BSplitItem(const BValue& value)
{
	member_allocate();
	member.value = value;
}
BSplitItem::BSplitItem(const BString& text, const BValue& value)
{
	member_allocate();
	member.text = text;
	member.value = value;
}
BSplitItem::BSplitItem(BIcon* icon, const BString& text, const BValue& value)
{
	member_allocate();
	member.icon = icon;
	member.text = text;
	member.value = value;
}
BSplitItem::BSplitItem(BImage* image, const BString& text, const BValue& value)
{
	member_allocate();
	member.image = image;
	member.text = text;
	member.value = value;
}
BSplitItem::BSplitItem(Graph graph, const BString& text, const BValue& value)
{
	member_allocate();
	member.graph = graph;
	member.text = text;
	member.value = value;
}
BSplitItem::~BSplitItem()
{
	member_release();
}

bool BSplitItem::setVisible(bool visible)
{
	if (member.visible != visible)
	{
		member.visible = visible;
		if (member.visible)
			this->emit(Signal_Show, true);
		else
			this->emit(Signal_Hide, false);
		member.dirtyCombox();
		return true;
	}
	return false;
}
bool BSplitItem::visible() const
{
	return member.visible;
}

bool BSplitItem::setForm(Form form)
{
	if (member.form != form)
	{
		member.form = form;
		member.dirty = true;
		member.dirtyCombox();
		this->emit(Signal_FormChanged, form);
		return true;
	}
	return false;
}
Form BSplitItem::form() const
{
	return member.form;
}

bool BSplitItem::setAlign(Align align)
{
	if (member.align != align)
	{
		member.align = align;
		member.dirty = true;
		member.dirtyCombox();
		this->emit(Signal_AlignChanged, align);
		return true;
	}
	return false;
}
Align BSplitItem::align() const
{
	return member.align;
}

bool BSplitItem::setSpacing(int spacing)
{
	if (member.spacing != spacing)
	{
		member.spacing = spacing;
		member.dirty = true;
		member.dirtyCombox();
		this->emit(Signal_SpacingChanged, spacing);
		return true;
	}
	return false;
}
int BSplitItem::spacing() const
{
	return member.spacing;
}

void BSplitItem::setGraph(Graph graph)
{
	if (member.graph != graph)
	{
		member.graph = graph;
		member.dirtyCombox();
		this->emit(Signal_GraphChanged, member.graph);
	}
}
Graph BSplitItem::graph() const
{
	return member.graph;
}

void BSplitItem::setColor(BByte r, BByte g, BByte b, BByte a)
{
	setColor(BColor(r, g, b, a));
}
void BSplitItem::setColor(const BColor& color)
{
	if (member.color != color)
	{
		member.color = color;
		if (member.splitButton)
			member.splitButton->fresh();
		this->emit(Signal_ColorChanged, member.color);
	}
}
const BColor& BSplitItem::color() const
{
	return member.color;
}

void BSplitItem::setImage(BImage* image)
{
	if (member.image != image)
	{
		member.image = image;
		member.dirtyCombox();
		this->emit(Signal_ImageChanged, member.image);
	}
}
BImage* BSplitItem::image() const
{
	return member.image;
}

void BSplitItem::setIcon(BIcon* icon)
{
	if (member.icon != icon)
	{
		member.icon = icon;
		member.dirtyCombox();
		this->emit(Signal_IconChanged, member.icon);
	}
}
BIcon* BSplitItem::icon() const
{
	return member.icon;
}

void BSplitItem::setText(const BString& text)
{
	if (member.text != text)
	{
		member.text = text;
		member.dirtyCombox();
		this->emit(Signal_TextChanged, member.text);
	}
}
const BString& BSplitItem::text() const
{
	return member.text;
}

void BSplitItem::setTips(const BString& tips)
{
	if (member.tips != tips)
	{
		member.tips = tips;
		object_member(this)->check_emit(Signal_TipsChanged, tips);
	}
}
const BString& BSplitItem::tips() const
{
	return member.tips;
}

void BSplitItem::setTextFormat(BTextFormat* textFormat)
{
	if (member.block.format() != textFormat)
	{
		member.block.setFormat(textFormat);
		if (textFormat)
		{
			if (member.splitButton)
				textFormat->styled(member.splitButton->realStyle());
			textFormat->changed(member.text);
		}
		this->emit(Signal_FormatChanged, textFormat);
		member.dirtyCombox();
	}
}
const BTextFormat* BSplitItem::textFormat() const
{
	return member.block.format();
}
BTextFormat* BSplitItem::textFormat()
{
	return member.block.format();
}

void BSplitItem::setBackground(BByte r, BByte g, BByte b, BByte a)
{
	setBackground(BColor(r, g, b, a));
}
void BSplitItem::setBackground(const BColor& background)
{
	if (member.background != background)
	{
		member.background = background;
		if (member.splitButton)
			member.splitButton->fresh();
	}
}
const BColor& BSplitItem::background() const
{
	return member.background;
}

void BSplitItem::setForeground(BByte r, BByte g, BByte b, BByte a)
{
	setForeground(BColor(r, g, b, a));
}
void BSplitItem::setForeground(const BColor& foreground)
{
	if (member.foreground != foreground)
	{
		member.foreground = foreground;
		if (member.splitButton)
			member.splitButton->fresh();
	}
}
const BColor& BSplitItem::foreground() const
{
	return member.foreground;
}

void BSplitItem::setValue(const BValue& value)
{
	if (member.value != value)
	{
		member.value = value;
		this->emit(Signal_ValueChanged, value);
	}
}
const BValue& BSplitItem::value() const
{
	return member.value;
}

int BSplitItem::index() const
{
	if (member.splitButton)
	{
		return member.splitButton->itemIndex(this);
	}
	return -1;
}
BRect BSplitItem::rect() const
{
	if (member.splitBoard)
	{
		BPoint offset = member.splitBoard->offset();
		return member.rect() + offset;
	}
	return member.rect();
}
BRect BSplitItem::iconRect() const
{
	if (member.splitBoard)
	{
		BPoint offset = member.splitBoard->offset();
		return member.ia_iconRect + offset;
	}
	return member.ia_iconRect;
}
BRect BSplitItem::textRect() const
{
	if (member.splitBoard)
	{
		BPoint offset = member.splitBoard->offset();
		return member.ia_textRect + offset;
	}
	return member.ia_textRect;
}
BRect BSplitItem::textArea() const
{
	if (member.splitBoard)
	{
		BPoint offset = member.splitBoard->offset();
		return member.ia_textArea + offset;
	}
	return member.ia_textArea;
}

BSplitButton* BSplitItem::splitButton()
{
	return member.splitButton;
}
const BSplitButton* BSplitItem::splitButton() const
{
	return member.splitButton;
}

